package net.rock.eshop.service;


import net.rock.eshop.entity.Address;
import net.rock.eshop.mapper.AddressMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressService {
    @Autowired
    AddressMapper addressMapper;

    public List<Address> showAddress(int userId){
        return addressMapper.showAddress(userId);
    }

    public void add(Address address){
        if (address.isDefault()) {
            addressMapper.unsetDefault(address.getUserId());
        }
        addressMapper.add(address);
    }

    public void del(Address address){
        addressMapper.del(address);
    }

    public void edit(Address address){
        if (address.isDefault()) {
            addressMapper.unsetDefault(address.getUserId());
        }
        addressMapper.edit(address);
    }
}
